<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //ES6 父类
    class Person {
      //构造器函数,当类被实例化的时候,实例化对象会直接调用原型对象上的constructor方法
      constructor(name, age) {
        this.name = name;
        this.age = age;
      }

      //address是实例化对象上的属性,可以不写在constructor中(不能被传参)
      address = "尚硅谷";

      //也是直接给实例化对象上添加方法
      do = function () {
        console.log("do");
      }

      //给原型对象扩展方法
      eat() {
        console.log("eat");
      }

      //静态属性
      static say = "hello react";
    }


    //ES6子类
    class Student extends Person {
      //只要子类书写constructor,必须在constructor中调用super，因为子类没有自己的this,需要调用super来构建自己的this
      constructor(name, age, score) {
        //super的参数是传递给父类的constructor的
        super(name, age)
        this.score = score;
      }
      study = "react";

      sleep() {
        console.log("上课睡觉");
      }
    }

    //如果子类没有constructor的话，子类的传参是直接给父类
    //如果子类有constructor的话,则泽类的传参是传递给子类的constructor的
    const s1 = new Student("laowang", 18, 100);
    console.log(s1, "s1");
  </script>
</body>

</html>